package com.example.unitorder.advice;

import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class CommonRestControllerAdvice {
	private static org.slf4j.Logger logger = LoggerFactory.getLogger(CommonRestControllerAdvice.class);

	@ExceptionHandler(value = RuntimeException.class)
	public ResponseEntity exception(RuntimeException e) {
		ResponseEntity.BodyBuilder bodyBuilder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR);
		ResponseEntity<RuntimeException> responseEntity = bodyBuilder.body(e);
		logger.error(e.getMessage(), e);
		return responseEntity;
	}


}
